package com.wuseguang.springcloud.mina.changYing;

public class MacUtils {

    /**
     * mac 转 6字节数组
     *
     * @param mac
     * @return
     */
    public static byte[] getMacBytes(String mac) {
        byte[] macBytes = new byte[6];
        String[] strArr = mac.split(":");

        for (int i = 0; i < strArr.length; i++) {
            int value = Integer.parseInt(strArr[i], 16);
            macBytes[i] = (byte) value;
        }
        return macBytes;
    }

    /**
     * 6字节数组转mac
     *
     * @param bytes
     * @return
     */
    public static String getMac(byte[] bytes) {
        StringBuilder value = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            String sTemp = Integer.toHexString(0xFF & bytes[i]);
            if (sTemp.length() == 1) {
                value.append("0");
            }
            value.append(sTemp).append(":");
        }
        return value.toString().substring(0, value.lastIndexOf(":")).toUpperCase();
    }
}
